import * as THREE from "three";
const br = Math.PI / 180
const wr = 180 / Math.PI
const Er = 1000
export function lngLatToMercator(t, e) {
  var i = [t, e];
  if (t instanceof Array) {
    i = t
  } else if (t instanceof Object) {
    i = [t.lng, t.lat]
  }
  var r = (i[0] * Er) / 180
  var o = Math.log(Math.tan(((90 + i[1]) * br) / 2)) / br;
  return { x: r, y: (o = (o * Er) / 180) };
}
export function mercatorToLngLat(t, e) {
  var i = [t, e];
  if (t instanceof Array) {
    i = t
  } else if (t instanceof Object) {
    i = [t.x, t.y]
  }
  var r = (i[0] / Er) * 180
  var o = (i[1] / Er) * 180;
  return {
    lng: r,
    lat: (o = wr * (2 * Math.atan(Math.exp(o * br)) - Math.PI / 2))
  };
}

export function lngLatToCoord (e, t, a) {
  return new THREE.Vector3(Math.cos(e / 180 * Math.PI) * Math.cos(t / 180 * Math.PI) * a, Math.sin(t / 180 * Math.PI) * a, -Math.sin(e / 180 * Math.PI) * Math.cos(t / 180 * Math.PI) * a)
}